
import { Address, beginCell, toNano } from "@ton/ton";
import { useTonConnectUI } from "@tonconnect/ui-react"

    const body = beginCell() //添加评论的转账 添加一个带有注释的负载
    .storeUint(0, 32) // write 32 zero bits to indicate that a text comment will follow 写32个零位来表示后面会有一个文本注释
    .storeStringTail("Hello, TON!") // write our text comment
    .endCell();

    // 转账TON
    const transaction:any = {
        validUntil: Date.now() + 5 * 60 * 1000, // 5 minutes for user to approve 5分钟有效
        messages: [
            {
                address:Address.parse("EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c").toString(), // destination address
                amount: toNano('0.2').toString(), //Toncoin in nanotons
                payload: body.toBoc().toString("base64") // payload with comment in body
            }
        ]
    }


    export const Transactions = ()=>{
        
        const [tonConnectUI] = useTonConnectUI();

        return (
            <div>
                <button onClick={() => tonConnectUI.sendTransaction(transaction)}>
                    Send transaction
                </button>
            </div>
        );
    }